/*
 * Copyright 2011-2012 Redia A/S
 * 
 * This file is part of Redias Library App for Android.
 *
 *  Redia Library App for Android is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Redia Library App for Android is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with Redia Library App for Android.  If not, see <http://www.gnu.org/licenses/>.
 */
package dk.redia.libraryapp;

import java.util.List;
import java.util.Observable;
import java.util.Observer;

import android.content.Intent;
import android.os.Bundle;
import dk.redia.lib.log.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import dk.redia.lib.model.InfoGalleriModel;
import dk.redia.lib.model.InfoObject;
import dk.redia.libraryapp.activityutils.LibraryAppActivity;
import dk.redia.libraryapp.adapters.ItHappensAdapter;
import dk.redia.libraryapp.utils.ResourceUtils;

public class ItHappensActivity extends LibraryAppActivity implements Observer {

	private static final String logTag = "ItHappensActivity";
	private ItHappensAdapter adapter;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
		setContentView(R.layout.ithappens);
		adapter = new ItHappensAdapter(this);
		ListView lv = (ListView)findViewById(R.id.itHappensListView);
		ImageView wideLogoImageView = (ImageView)findViewById(R.id.itHappensWideLogoImageView);
	    wideLogoImageView.setImageResource(ResourceUtils.getWideLogoResourceId());
		lv.setAdapter(adapter);
		InfoGalleriModel.getInstance().addInfoObjectsObserver(this);
		update();
	}
	
	private void update() {
		update(null, null);
	}
	
	public void update(Observable observable, Object data) {
		List<InfoObject> ios = InfoGalleriModel.getInstance().getInfoObjects(InfoObject.TYPE_ARRANGEMENT);
		if (ios.size()==0) {
			return;
		}
		adapter.clear();
		adapter.addAll(ios);
	}

	public void onItHappensItemClicked(View v) {
		InfoObject io = (InfoObject)v.getTag();
		Log.d(ItHappensActivity.logTag, "It happens item clicked");
		Intent intent = new Intent(this, NewsItemDetailsActivity.class);

		intent.putExtra("infoObjectId", io.getAbsoluteId().toString());
		startActivity(intent);
	}
}
